﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using LayerEntity.Almacen;

namespace System2012.Listados
{
    public partial class frmListarAlmacen : DevExpress.XtraEditors.XtraForm
    {
        public ArrayList data;
        int indexRow;
        DataTable dtbAlm;
        string idAlm;
        string idProd;
        public frmListarAlmacen()
        {
            this.InitializeComponent();
        }

        public frmListarAlmacen(ArrayList dat)
        {
            this.InitializeComponent();
            this.idAlm = dat[0].ToString();
            this.idProd = dat[1].ToString();
        }

        private void panelControMain_Paint(object sender, PaintEventArgs e)
        {
        }

        private void Seleccionar()
        {
            this.data = new ArrayList();
            this.data.Add(this.dtbAlm.Rows[this.indexRow]["id_almacen"]);
            this.data.Add(this.dtbAlm.Rows[this.indexRow]["saldos"]);
            this.Close();
        }

        private void BGWListarAlm_DoWork(object sender, DoWorkEventArgs e)
        {
            EAlmacen objAl = new EAlmacen();
            StringBuilder cadena = new StringBuilder();
            cadena.AppendFormat("where id_producto='{0}", this.idProd);
            cadena.Append("'");
            objAl.Condicion = cadena.ToString();
            e.Result = System2012.SystemUtils.RecordmanagerAlmacen.GetListaStockAlamcen(objAl);
        }

        private void BGWListarAlm_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.dtbAlm = (DataTable)e.Result;
            this.gridControl1.DataSource = e.Result;
        }

        private void frmListarAlmacen_Load(object sender, EventArgs e)
        {
            if (!this.BGWListarAlm.IsBusy)
            {
                this.BGWListarAlm.RunWorkerAsync();
            }
        }

        private void gridControl1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                this.Seleccionar();
            }
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            this.indexRow = e.FocusedRowHandle;
        }

        private void gridControl1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Seleccionar();
        }
    }
}